<?php
namespace app\mobile\controller;

use app\model\Theme; 

class Searchorder extends Base
{
    public function Searchorder()
    {
global $_G, $_P;
// $system    = $_G['system'];
$themeid   = intval($_P['themeid']);
$mobile   = trim($_P['search_txt']);
if($themeid < 0){
    return_msg('活动入口不正确');
}
if(empty($mobile)){
    $result['errcode'] = 0;
    $result['msg'] = '手机未输入';
	return_msg($result, '', 'ajax');
}


$config = 	Theme::getConfig($themeid);

$result=  array();

$sql = "SELECT * FROM " . tablename (t_record) . "
							WHERE themeid =:themeid and mobile = :mobile  and status > 0";
$record = db_find($sql, array(":themeid"=>$themeid,":mobile"=>$mobile));

$p3 = array(":openid"=>$_G['openid'],":themeid"=>$themeid);
$recordinfo = db_find ( "SELECT * FROM " . tablename (t_record) . "
                                WHERE themeid =:themeid
                                        and openid = :openid and type<>8 order by id desc limit 1",$p3);

if ($config['isrecent']==1 && empty($recordinfo)) {
	if (!empty($record)) {
	    $result['errcode'] = 1;
	    $result['msg'] = $_G['siteroot']. createMobileUrl("index",array("themeid"=>$themeid,"fromuid"=>$_P['fromuid'],"fopenid"=>$_P['fopenid'],"workerid"=>$_P['workerid'],"recordid"=>$record["id"],"showtuan"=>1));
	}else{
	    $result['errcode'] = 0;
	    $result['msg'] = '手机' . $mobile . '未搜到';
	}
}else{
	if (!empty($record)) {
	    $result['errcode'] = 0;
	    $result['msg'] = '手机' . $mobile . '已支付';
	}else{
	    $result['errcode'] = 0;
	    $result['msg'] = '手机' . $mobile . '未支付';
	}
}

return_msg($result, '', 'ajax');
}
}